package edu.com.wjt219971332.dao;

import edu.com.wjt219971332.entity.Matchup;
import org.apache.ibatis.annotations.*;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface MatchupDao {

    @Select("SELECT * FROM matchup WHERE matchupid = #{matchupid}")
    Matchup queryById(Integer matchupid);

    @Select("SELECT * FROM matchup LIMIT #{pageable.offset}, #{pageable.pageSize}")
    List<Matchup> queryAllByLimit(Matchup matchup, @Param("pageable") Pageable pageable);

    @Select(" select count(1) from matchup")
    long count(Matchup matchup);

    @Insert("INSERT INTO matchup (competitionid, asinger, bsinger, asingerstatus, bsingerstatus, asingername, bsingername) VALUES (#{competitionid} ,#{asinger}, #{bsinger}, #{asingerstatus}, #{bsingerstatus}, #{asingername}, #{bsingername})")
    @Options(useGeneratedKeys = true, keyProperty = "matchupid")
    int insert(Matchup matchup);


    int insertBatch(@Param("entities") List<Matchup> entities);


    int insertOrUpdateBatch(@Param("entities") List<Matchup> entities);

    @Update("UPDATE matchup SET username = #{username}, account = #{account},password = #{password}, role = #{role} WHERE userid = #{userid}")
    int update(Matchup matchup);

    @Delete("DELETE FROM matchup WHERE matchupid = #{matchup}")
    int deleteById(Integer matchupid);
    @Select("SELECT * FROM matchup WHERE name LIKE CONCAT('%', #{asinger}, '%') OR name LIKE CONCAT('%', #{bsinger}, '%')")
    List<Matchup> queryByusername(String name);
}

